﻿Namespace Sigortali.Prim
	Module Functions

		'Function BorcHesapla(Token As Token, sno As Integer, d1 As Date, d2 As Date, odetar As Date) As Recordset
		'	Dim A As New BorcHesabi
		'	A.Token = Token
		'	A.Tarih1 = d1
		'	A.Tarih2 = d2
		'	A.OdemeTarihi = odetar
		'	A.sno = sno
		'	A.BorcHesapla()
		'	Return A.PrimBorclari
		'End Function

		'Class BorcHesabi
		'	Public Token As Token
		'	Public Bordrolar As Recordset
		'	Public PrimBorclari As Recordset
		'	Public Tarih1, Tarih2, OdemeTarihi As Date
		'	Public sno As Integer

		'	Dim Yatirimlar As Recordset
		'	Dim Raporlar As Recordset
		'	Dim GirisCikis As Recordset
		'	Dim Basamaklar As Recordset
		'	Dim DogumTar, EmeklilikTar As Date

		'	Sub New()
		'		PrimBorclari = New Recordset("bordrotar(d),basamak(i),gun(i),h(i),d(i),j(i),e(i),l(i),has(i),ana(i),isk(i),hborc(m),jborc(m),lborc(m),anapara(m),ceza(m),toplam(m),tehlike(i)")
		'		Bordrolar = New Recordset("bordrotar(d),bordro(s),isyerino(s),anapara(m),ceza(m),toplam(m),tur(s)")
		'	End Sub

		'	Sub TablolariOku()
		'		Dim Rs As Recordset = Sigortali.SnoAra(Token, sno)
		'		DogumTar = Rs("dtar")
		'		EmeklilikTar = If(IsDBNull(Rs("maasbtar")), "2099/01/01", Rs("maasbtar"))
		'		Yatirimlar = Hukuk.Af.Tablo.Yatirimlar(Token, sno)
		'		Raporlar = Hukuk.Af.Tablo.Raporlar(Token, sno)
		'		GirisCikis = Hukuk.Af.Tablo.GirisCikis(Token, sno)
		'		Basamaklar = Hukuk.Af.Tablo.Basamaklar(Token, sno)
		'	End Sub

		'	Sub BorcHesapla()
		'		Dim Donem As String = ""
		'		Dim Tarih As Date = Tarih1
		'		TablolariOku()
		'		Bordrolar.Rows.Clear()
		'		PrimBorclari.Rows.Clear()
		'		Do Until Tarih > Tarih2
		'			BorcHesaplaAyIcin(Tarih)
		'			Tarih = Tarih.AddDays(1 - Tarih.Day).AddMonths(1)
		'		Loop
		'	End Sub

		'	Sub BorcHesaplaAyIcin(ByVal Tarih As Date)
		'		Dim Dr As DataRow
		'		Dim Interval As New Interval(Tarih, Tarih.AddDays(1 - Tarih.Day).AddMonths(1).AddDays(-1))
		'		Dim Isyerleri As New Collection
		'		Dim Isyeri As DataRow = Nothing
		'		For Each Row As DataRow In GirisCikis.Rows
		'			Dim IsInterval As New Interval(Row("Tarih1"), Row("Tarih2"))
		'			If Interval.OverlappingDays(IsInterval) > 0 Then
		'				Isyerleri.Add(IsInterval)
		'				If Isyeri Is Nothing Then
		'					Isyeri = Row
		'				ElseIf Row("tehlike") > Isyeri("tehlike") Then
		'					Isyeri = Row
		'				End If
		'			End If
		'		Next
		'		If Isyerleri.Count = 0 Then Exit Sub
		'		Dr = PrimBorclari.Rows.Add(Tarih, 1, Interval.OverlappingDays(Isyerleri(1)), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
		'		Dr("tehlike") = Isyeri("tehlike")
		'		For Each Row As DataRow In Raporlar.Rows
		'			Dr(Row("tur")) = Dr(Row("tur")) + Interval.OverlappingDays(New Interval(Row("Tarih1"), Row("Tarih2")))
		'		Next
		'		For Each Row As DataRow In Yatirimlar.Select("bordrotar = '" & Tarih.ToString("yyyy-MM-01") & "'").Rows
		'			If InStr("DHEJL", Row("bordro")) > 0 Then Dr(Row("bordro")) = Dr(Row("bordro")) + Row("pogs")
		'		Next
		'		Dim GunSayisi As Integer = Dr("gun") - (Dr("has") + Dr("ana") + Dr("isk"))
		'		If GunSayisi <= 0 Then Exit Sub
		'		If Dr("h") + Dr("j") + Dr("l") >= GunSayisi Then
		'			PrimBorclari.Rows.Remove(Dr)
		'			Exit Sub
		'		End If
		'		For Each Row As DataRow In Basamaklar.Rows
		'			If Row("tarih") > Tarih.AddMonths(1).AddDays(-1) Then Exit For
		'			Dr("basamak") = Row("basamak")
		'		Next
		'		If Dr("basamak") < 6 And DogumTar.AddYears(31) <= Dr("bordrotar") Then Dr("basamak") = 6
		'		If Tarih < EmeklilikTar And Dr("l") = 0 And Dr("d") = 0 Then
		'			Dr("hborc") = GunSayisi - Dr("h")
		'		ElseIf Tarih >= EmeklilikTar And Dr("l") = 0 And Dr("e") = 0 And Dr("d") = 0 Then
		'			Dr("jborc") = GunSayisi - Dr("j")
		'		ElseIf Dr("l") >= GunSayisi Then
		'			PrimBorclari.Rows.Remove(Dr)
		'			Exit Sub
		'		Else
		'			If Tarih < EmeklilikTar Then
		'				Dr("lborc") = Dr("d") - Dr("l")
		'				Dr("hborc") = Dr("gun") - Dr("lborc") - Dr("l") - Dr("h")
		'			Else
		'				Dr("lborc") = Dr("e") + Dr("d") - Dr("l")
		'				Dr("jborc") = Dr("gun") - Dr("lborc") - Dr("l") - Dr("j")
		'			End If
		'		End If
		'		For Each Bordro As Object In Split("h-j-l", "-")
		'			If Dr(Bordro & "borc") > 0 Then
		'				Dim Oran As Decimal = SSD.Prim.Oran(Tarih, UCase(Bordro), Isyeri("tehlike"))
		'				Dim Anapara As Decimal = SSD.Prim.Tutar(Token, Tarih, 1, Dr("basamak"), OdemeTarihi) * Dr(Bordro & "borc") / 30 * Oran / 100
		'				Dim Ceza As Decimal = SSD.Prim.GecikmeZammiHesabi(UCase(Bordro), Tarih, OdemeTarihi) * Anapara / 100
		'				Dr("anapara") += Anapara
		'				Dr("ceza") += Ceza
		'				Bordrolar.Rows.Add(Tarih, UCase(Bordro), Isyeri("isyerino"), Anapara, Ceza, Anapara + Ceza, "P")
		'			End If
		'		Next
		'		Dr("toplam") = Dr("anapara") + Dr("ceza")
		'	End Sub

		'End Class

	End Module
End Namespace


